/*
  操作dom的公用方法
*/

const elementStyle = document.createElement('div').style

const vendor = (() => {
  const transformNames = {
    webkit: 'webkitTransform',
    Moz: 'MozTransform',
    O: 'OTransform',
    ms: 'msTransform',
    standard: 'transform'
  }

  for (let key in transformNames) {
    if (elementStyle[transformNames[key]] !== undefined) {
      return key
    }
  }

  return false
})()

// 行内样式兼容写法
export const prefixStyle = (style) => {
  if (vendor === false) {
    return false
  }

  if (vendor === 'standard') {
    return style
  }

  return `-${vendor}-${style}`
}

// 阻止冒泡事件兼容写法
export const CancelBubble = (event) => {
  if (event.stopPropagation) {
    event.stopPropagation()
  } else {
    event.cancelBubble = true
  }
}

// 取消默认事件兼容
export const returnFalse = (event) => {
  if (event.preventDefault) {
    event.preventDefault()
  } else {
    window.event.returnValue = false
  }
  return false
}
